package com.saltlux.tdd.algorithm;

import java.util.Comparator;

import org.junit.Assert;
import org.junit.Test;

public class InsertionSortTester {
	@Test
	public void testShortArraySorting() {
		String[] fixture = new String[] { "5", "4", "6" };

		InsertionSort sort = new InsertionSort();

		StringValueComparator comparator = new StringValueComparator();
		sort.sort(fixture, comparator);

		Assert.assertArrayEquals(new String[] { "4", "5", "6" }, fixture);
	}

	@Test
	public void testSorting() {
		String[] fixture = new String[] { "saltlux", "discovery", "dor",
				"storm", "sor", "ssamzie", "taskscheduler", "indexagent",
				"dicsearcher" };

		InsertionSort sort = new InsertionSort();

		StringValueComparator comparator = new StringValueComparator();
		sort.sort(fixture, comparator);

		Assert.assertArrayEquals(new String[] { "dicsearcher", "discovery",
				"dor", "indexagent", "saltlux", "sor", "ssamzie", "storm",
				"taskscheduler" }, fixture);
	}

	@Test
	public void testSortingByLength() {
		String[] fixture = new String[] { "saltlux", "discovery", "dor",
				"storm", "sor", "ssamzie", "taskscheduler", "indexagent",
				"dicsearcher" };

		InsertionSort sort = new InsertionSort();

		Comparator comparator = new StringLengthComparator();
		sort.sort(fixture, comparator);

		Assert.assertArrayEquals(new String[] { "dor", "sor", "storm",
				"saltlux", "ssamzie", "discovery", "indexagent", "dicsearcher",
				"taskscheduler" }, fixture);
	}
}
